﻿//********************************************************************************//
//创建日期：<创建日期，2016-02-26>
//创建作者：<郭登杰，guodengjie@shanghai3h.com>
//功能说明：业务员调动
//********************************************************************************//
using System;
using Entity;
using BLL;
using BLL.Access;
using System.Data;
using Web.Class;

namespace Web.Pages.YongShui
{
    public partial class YeWuYuanDD : BasePage
    {
        #region 属性

        #endregion

        #region 变量

        /// <summary>
        /// 数据访问操作类
        /// </summary>
        SpHelper _spHelper = new SpHelper();

        /// <summary>
        /// 日志BLL
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();

        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            {
                InitControl();
            }
        }

        /// <summary>
        /// 响应前台回调
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            if (e.Parameter == "tab1")
            {
                _spHelper.P_YS_UPDATE_JUGLK_YWY(null, Convert.ToInt32(this.cmbMuDiYWY.Value), null, 0, LoginInfo.CurrentUser.UserID.ToString(), DateTime.Now, Convert.ToInt32(this.cmbYuanYWY.Value));
            }
            else if (e.Parameter == "tab2")
            {
                _spHelper.P_YS_UPDATE_JUGLK_YWY(this.cmbJu.Value.ToString(), Convert.ToInt32(this.cmbJuMuDiYWY.Value), null, 1, LoginInfo.CurrentUser.UserID.ToString(), DateTime.Now,null);
            }
            else if (e.Parameter == "tab3")
            {
                _spHelper.P_YS_UPDATE_JUGLK_YWY(this.cmbGLK.Value.ToString(), Convert.ToInt32(this.cmbGLKMuDiYWY.Value), null, 2, LoginInfo.CurrentUser.UserID.ToString(), DateTime.Now, null);
            }
            else if (e.Parameter == "tab4")
            {
                _spHelper.P_YS_UPDATE_JUGLK_YWY(this.cmbGLK2.Value.ToString(), Convert.ToInt32(this.cmbGLK2MuDiYWY.Value), null, 3, LoginInfo.CurrentUser.UserID.ToString(), DateTime.Now, Convert.ToInt32(this.cmbGLK2YuanYWY.Value));
            }
            e.Result = e.Parameter + "|0|操作成功！";
        }

        /// <summary>
        /// 加载管理块原业务员
        /// </summary>
        protected void cmbGLK2YuanYWY_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e)
        {
            PageTools.BindComboBox(
                this.cmbGLK2YuanYWY, this._spHelper.P_COMMON_YWYGET(BusinessTool.WType, "-", string.Format("USERID in (select S_YEWUY from YS_YG_YONGHUXX where I_JLZT=0 and S_GUANLIKBH='{0}')", Convert.ToString(cmbGLK2.Value)), null).Tables[0]
            );
            //LoadYWYByGLK(this.cmbGLK2YuanYWY, this.cmbGLK2);
        }
        /*
        /// <summary>
        /// 加载管理块原业务员
        /// </summary>
        /// <param name="cmb">业务员cmb</param>
        /// <param name="cmbGLK">管理块cmb</param>
        private void LoadYWYByGLK(DevExpress.Web.ASPxComboBox cmb, DevExpress.Web.ASPxComboBox cmbGLK)
        {
            if (this.cmbGLK.SelectedIndex != -1)
            {
                if (!string.IsNullOrEmpty(Convert.ToString(cmbGLK.Value)))
                {
                    PageTools.BindComboBox(
                         cmb, BusinessTool.GetTextAndValue(
                             "view_as_userinfo", "USERNAME", "USERID", "-", string.Format("USERID in (select S_YEWUY from YS_YG_YONGHUXX where I_JLZT=0 and S_GUANLIKBH='{0}')", Convert.ToString(cmbGLK.Value))
                         ).Tables[0]
                     );
                    if (cmb.Items.Count != 0)
                    {
                        cmb.SelectedIndex = 0;
                    }
                    else
                    {
                        cmb.Value = "";
                    }
                }
            }
            else
            {
                cmb.DataSource = null;
                cmb.DataBind();
            }
        }
        */
        #endregion

        #region 方法

        /// <summary>
        /// 初始化控件
        /// </summary>
        private void InitControl()
        {
            //根据操作人获取站点
            DataTable dtZhanDian = BusinessTool.GetTextAndValue("View_AS_UserInfo", "ZHANDIANMC", "ZHANDIANBH", null, string.Format("USERID={0}", LoginInfo.CurrentUser.UserID)).Tables[0];
            string zhendianBH = dtZhanDian.Rows[0]["VALUE"].ToString();
            //***加载用户业务员修改***//
            //加载当前所有用户正使用的业务员
            PageTools.BindComboBox(
                this.cmbYuanYWY, this._spHelper.P_COMMON_YWYGET(BusinessTool.WType, "-", "USERID in (select S_YEWUY from YS_YG_YONGHUXX where I_JLZT=0)",null).Tables[0]
            );
            this.cmbYuanYWY.Value = "";
            //获取所有业务员
            DataTable ywyAll = this._spHelper.P_COMMON_YWYGET(BusinessTool.WType, "-",null, null).Tables[0];
            //DataTable ywyAll = BusinessTool.GetTextAndValue("View_AS_UserInfo", "USERNAME", "USERID", "-", string.Format("ROLENAME like '%业务员%'")).Tables[0];
            //加载所有业务员
            PageTools.BindComboBox(this.cmbMuDiYWY, ywyAll);
            if (this.cmbMuDiYWY.Items.Count != 0)
            {
                this.cmbMuDiYWY.SelectedIndex = 0;
            }
            this.cmbMuDiYWY.Value = "";
            //***加载局业务员修改***//
            //加载局
            PageTools.BindComboBox(
                this.cmbJu, BusinessTool.GetTextAndValue(
                    "YS_JX_JUXINX", "S_MINGCHENG", "S_BIANHAO", "-", "i_jlzt=0"
                ).Tables[0]
            );
            this.cmbJu.Value = "";
            //加载所有业务员
            PageTools.BindComboBox(this.cmbJuMuDiYWY, ywyAll);
            this.cmbJuMuDiYWY.Value = "";

            //***加载管理块业务员修改***//
            //获取管理块
            DataTable glk = BusinessTool.GetTextAndValue("YS_JX_GUANLIK", "S_GUANLIKMC", "S_GUANLIKH", "-", "i_jlzt=0").Tables[0];
            //加载管理块
            PageTools.BindComboBox(this.cmbGLK, glk);
            this.cmbGLK.Value = "";
            //加载所有业务员
            PageTools.BindComboBox(this.cmbGLKMuDiYWY, ywyAll);
            this.cmbGLKMuDiYWY.Value = "";

            //***加载业务员管理块选项卡***//
            //加载管理块
            PageTools.BindComboBox(this.cmbGLK2, glk);
            this.cmbGLK2.Value = "";
            //加载管理块目的业务员
            PageTools.BindComboBox(this.cmbGLK2MuDiYWY, ywyAll);
            this.cmbGLK2MuDiYWY.Value = "";
        }

        #endregion        
    }
}